home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Mops 2.7 / Mops source / Nuc source / Defn.asm next >
Assembly Source File  |  1995-09-17  |  11KB  |  690 lines

  1. ; This file contains the definition of the macros and other items which
  2. ; generally define the structure of the implementation.
  3.  
  4.     mexp    0    ; Set non-zero for expansions
  5.  
  6. ;    =======================
  7.  
  8. ; Flag codes for various word types.  The actual values are quite
  9. ; arbitrary, but let us do conditional comparison on numeric values
  10. ; rather than strings, which is faster and uses less memory during
  11. ; assembly.
  12.  
  13. inline    equ    0
  14. docode    equ    1
  15. docol    equ    3
  16. docon    equ    5
  17. doval    equ    6
  18. doObj    equ    7
  19. dovbl    equ    8
  20. dovect    equ    9
  21. doDynVect    equ    4
  22. spec    equ    10
  23. xinfo    equ    11
  24. nocode    equ    12
  25. doObjPtr    equ    13
  26. xinfoN    equ    14
  27.  
  28. xinfoMk    equ    $4E58    ; This is  UNLK A0  which never appears in
  29.             ;  Mops code.  (Pretty unlikely anywhere!!)
  30.  
  31. ;    ========================
  32.  
  33. FCBlen    equ    204
  34. HOLDlen    equ    30
  35. PADlen    equ    200
  36. TIBlen    equ    400
  37. ErrDumpLen    equ    200
  38. MaxDump    equ    (ErrDumpLen / 8) - 5
  39.  
  40. FBlkLen    equ    FCBlen + HOLDlen + PADlen + TIBlen + ErrDumpLen + 8
  41.                 ; The extra 8 is for the object header
  42.  
  43. ;    ========================
  44.  
  45. hbase    equ    0
  46.  
  47. ; Codes for handler routines.  These must all be negative.
  48.  
  49. inl_h    equ    -1
  50.  
  51. ; The following codes are used to table jump to the right routine within
  52. ; Handlers, and so must be negative and even.
  53.  
  54. col_h    equ    -2
  55. call_h    equ    col_h
  56. const_h    equ    -4
  57. val_h    equ    -6
  58. create_h    equ    -8
  59. vect_h    equ    -10
  60. pm_h    equ    -12
  61. at_h    equ    -14
  62. store_h    equ    -16
  63. callstr_h    equ    -18
  64. reg_h    equ    -20
  65. obj_h    equ    -22
  66. does_h    equ    -24
  67. loc_h    equ    -26
  68. LitAddr    equ    -28
  69. PushDesc_h    equ    -30
  70. cmp_h    equ    -32
  71. hLiteral    equ    -34
  72. CompExit    equ    -36
  73. CompJSRLong    equ    -38
  74. pif    equ    -40
  75. compPlLoop    equ    -42
  76. hmentry    equ    -44
  77. hplentry    equ    -46
  78. heb    equ    -48
  79. hStkObj    equ    -50
  80. hDoEx    equ    -52
  81. hgenaddr    equ    -54
  82. hgenxaddr    equ    -56
  83. class_h    equ    -58
  84. hcompimp    equ    -60
  85. objPtr_h    equ    -62
  86. bit_h    equ    -64
  87. swap_h    equ    -66
  88. hLoadBA    equ    -68
  89. FixDoes    equ    -70
  90. hPatch    equ    -72
  91. Floc_h    equ    -74
  92. Fcon_h    equ    -76
  93. Fval_h    equ    -78
  94. FP1_h    equ    -80
  95. FP2_h    equ    -82
  96. FPcmp_h    equ    -84
  97. hcompFPUL    equ    -86
  98. FCRcon_h    equ    -88
  99. class_in_mod_h    equ    -90
  100. imported_h    equ    -92
  101. hColA    equ    -94
  102. shift_h    equ    -96
  103. hDefnEnd    equ    -98
  104. Fat_h    equ    -100
  105. Fst_h    equ    -102
  106. builds_h    equ    -104
  107. MultDiv_h    equ    -106
  108. Move_h    equ    -108
  109. AlignedMove_h    equ    -110
  110. hNoOpt    equ    -112
  111. colNoOpt_h    equ    -114
  112. hComputedJMP    equ    -116
  113. dynVect_h    equ    -118
  114. sysCall_h    equ    -120
  115. RBsysCall_h    equ    -122
  116.  
  117. ;        =======================
  118.  
  119. ;                MACROS
  120.  
  121. ;        =======================
  122.  
  123. ; Push and pop macros - modified to use A6 instead of A7.
  124.  
  125. push.b    macrox    &1
  126.     move.b    &1,-(a6)
  127.     endm
  128.  
  129. push.w    macrox    &1
  130.     move.w    &1,-(a6)
  131.     endm
  132.  
  133. push    macrox    &1
  134.     move.w    &1,-(a6)
  135.     endm
  136.  
  137. push.l    macrox    &1
  138.     move.l    &1,-(a6)
  139.     endm
  140.  
  141. pop.b    macrox    &1
  142.     move.b    (a6)+,&1
  143.     endm
  144.  
  145. pop.w    macrox    &1
  146.     move.w    (a6)+,&1
  147.     endm
  148.  
  149. pop    macrox    &1
  150.     move.w    (a6)+,&1
  151.     endm
  152.  
  153. pop.l    macrox    &1
  154.     move.l    (a6)+,&1
  155.     endm
  156.  
  157.  
  158. ; Since we are using A5 as the module base reg, we need to reset it to CurrentA5
  159. ; over many system calls.  We also need to save RP (A7) in case the system calls
  160. ; us back (i.e. to a :PROC).  So here we define macros to set up for a system call
  161. ; then restore things after the system returns.
  162.  
  163. SavA5    macrox
  164.     jsr    DoSavA5-base(a3)
  165.     endm
  166.  
  167. RstA5    macrox
  168.     exg    a6,a7
  169.     move.l    (a7)+,a5
  170.     endm
  171.  
  172.  
  173. ; N assembles a push of the parameter as a literal number, with optimization.
  174.  
  175. N    macrox    &1
  176.     if    &1 = 0
  177.     CLR.L    -(A6)
  178.     else
  179.     if    (&1 < 128) or (-(&1) <= 128)
  180.     MOVEQ    #&1,D0
  181.     PUSH.L    D0
  182.     else
  183.     PUSH.L    #&1
  184.     endi
  185.     endi
  186.     endm
  187.  
  188.  
  189. ADD_M    macrox    &1
  190.     if    (&1 <= 8)
  191.     ADDQ.L    #&1,(A6)
  192.     else
  193.     ADDI.L    #&1,(A6)
  194.     endi
  195.     endm
  196.  
  197. SUB_M    macrox    &1
  198.     if    (&1 <= 8)
  199.     SUBQ.L    #&1,(A6)
  200.     else
  201.     SUBI.L    #&1,(A6)
  202.     endi
  203.     endm
  204.  
  205.  
  206. ; CONSTANTs - fetches of these are optimized, since we have the value
  207. ; available.
  208.  
  209. CONST    macrox    &1,&2,&3,&4    ; len, name, label, value
  210.     head    &1,&2,&3,docon
  211.     h    const_h
  212. &3    dc.l    &4
  213. &3_con    equ    &4
  214.     endm
  215.  
  216. NCONST    macrox    &1,&2    ; Constant with no head
  217.     nohead    &1,docon
  218.     h    const_h
  219. &1    dc.l    &2
  220. &1_con    equ    &2
  221.     endm
  222.  
  223.  
  224. FCon    macrox    &1
  225.     if    &1_con = 0
  226.     CLR.L    -(A6)
  227.     else
  228.     if    (&1_con < 128) or (-(&1_con) <= 128)
  229.     MOVEQ    #&1_con,D0
  230.     PUSH.L    D0
  231.     else
  232.     PUSH.L    &1-base(A3)
  233.     endi
  234.     endi
  235.     endm
  236.  
  237.  
  238. ; VALUEs - these have 3 "methods", fetch, increment, store.
  239.  
  240. VALU    macrox    &1,&2,&3,&4    ; len, name, label, value
  241.     head    &1,&2,&3,doval
  242.     h    val_h
  243.     if    "&4" <> ""
  244. &3    dc.l    &4
  245.     else
  246. &3    dc.l    0
  247.     endi
  248.     endm
  249.  
  250. NVALU    macrox    &1,&2    ; Value with no header
  251.     nohead    &1,doval
  252.     h    val_h
  253.     if    "&2" <> ""
  254. &1    dc.l    &2
  255.     else
  256. &1    dc.l    0
  257.     endi
  258.     endm
  259.  
  260. FVal    macrox    &1
  261.     PUSH.L    &1-base(A3)
  262.     endm
  263.  
  264. IncVal    macrox    &1
  265.     POP.L    D0
  266.     ADD.L    D0,&1-base(A3)
  267.     endm
  268.  
  269. ToVal    macrox    &1
  270.     POP.L    &1-base(A3)
  271.     endm
  272.  
  273. ZVal    macrox    &1
  274.     CLR.L    &1-base(A3)
  275.     endm
  276.  
  277.  
  278. ; Variables.  Note in this assembly we don't automatically allocate
  279. ; storage for a variable.  An explicit  byte n  or whatever must be
  280. ; done.
  281.  
  282. VARBL    macrox    &1,&2,&3,&4
  283.     head    &1,&2,&3,dovbl
  284.     h    create_h
  285. &3
  286.     endm
  287.  
  288. rVbl    macrox    &1
  289.     LEA    &1,A0
  290.     PUSH.L    A0
  291.     endm
  292.  
  293.  
  294. ; Vectors.  These have 3 "methods" - execute, fetch, store.
  295. ; System vectors have a default value, 4 bytes after the normal value.
  296. ; The normal value is a relocatable address, but we assume the default
  297. ; is within the normal dic range, so we use a straight JMP.
  298. ; Dynamic vectors (new with Mops 2.5) are useful for calling words in a (locked)
  299. ; module.  They have to be set at run time since they use an absolute address.
  300.  
  301. SVECT    macrox    &1,&2,&3,&4    ; len, name, label, default value
  302.     head    &1,&2,&3,dovect
  303.     h    vect_h
  304. &3    jsr    DoExVect-base(a3)
  305.     dc.l    0
  306.     if    "&4" <> ""
  307.     bra    &4
  308.     else
  309.     bra    null
  310.     endi
  311.     endm
  312.  
  313. DynVECT    macrox    &1,&2,&3        ; len, name, label
  314.     head    &1,&2,&3,doDynVect
  315.     h    dynVect_h
  316. &3    jsr    DoExDynVect-base(a3)
  317.     dc.l    0
  318.     endm
  319.  
  320. NVECT    macrox    &1    ; Vector with no header and no default
  321.     nohead    &1,dovect
  322. &1    jsr    DoExVect-base(a3)
  323.     dc.l    0
  324.     endm
  325.  
  326.  
  327. ExVect    macrox    &1
  328.     jsr    &1-base(a3)
  329.     endm
  330.  
  331. SetVect    macrox    &1,&2
  332.     lea    &1,a0
  333.     push.l    a0
  334.     lea    &2+4-base(a3),a0
  335.     jsr    DoToVect-base(A3)
  336.     endm
  337.  
  338. ClrVect    macrox    &1
  339.     clr.l    &1+4-base(a3)
  340.     endm
  341.  
  342. ExDynVect    macrox    &1
  343.     jsr    &1-base(a3)
  344.     endm
  345.  
  346. ;        ================
  347.  
  348. pushop    macrox    &1
  349.     PUSH.W    &1-base(A3)
  350.     CLR.W    -(A6)
  351.     endm
  352.  
  353. compop    macrox    &1
  354.     pushop    &1
  355.     parms    wcomma
  356.     endm
  357.  
  358.  
  359. ; Compyl is the macro equivalent of COMPILE (now replaced by POSTPONE).
  360. ; It assembles a call to (COMP) which either moves in inline code or calls
  361. ; the compilation handler for the given word.
  362.  
  363. compyl    macrox    &1
  364.     rVbl    &1
  365.     bsr    doPcomp
  366.     endm
  367.  
  368.  
  369. NEXT    macrox
  370.     rts
  371.     endm
  372.  
  373. H    macrox    &1
  374.     dc.w    &1
  375.     endm
  376.  
  377. INL    macro    &1
  378.     dc.w    .xx-*-2
  379. &1    &1_m
  380. .xx    rts
  381.     endm
  382.  
  383. USE    macrox    &1
  384. &1    &1_m
  385.     rts
  386.     endm
  387.  
  388.  
  389. TOKEN    macrox    &1
  390.     if    &1_t = inline
  391.     &1_m
  392.     else
  393.     if    (&1_t = doval) or (&1_t = doObjPtr)
  394.     FVal    &1
  395.     else
  396.     if    &1_t = docon
  397.     FCon    &1
  398.     else
  399.     if    (&1_t = dovbl) or (&1_t = doObj)
  400.     rVbl    &1
  401.     else
  402.     if    &1_t = dovect
  403.     exVect    &1
  404.     else
  405.     BSR    &1
  406.     endi
  407.     endi
  408.     endi
  409.     endi
  410.     endi
  411.     endm
  412.  
  413.  
  414. HCODE    macrox    &1,&2
  415.     if    "&2" <> ""
  416.     dc.w    &2
  417.     else
  418.     dc.w    &1
  419.     endi
  420.     endm
  421.  
  422.  
  423. ; CODE is called by HEAD and NOHEAD.
  424. ; It's easily the most complex macro here, so I'd better give some commentary:
  425. ; The first if..endi section handles the case where we need a descriptor pushed
  426. ; at compile-time.  This is indicated by the "pushDesc_h" handler code.  Then
  427. ; comes the xinfoMk which tells EXECUTE that this isn't code, then the byte count
  428. ; of the extra info, which in this case is 2 bytes for the descriptor type & subtype,
  429. ; and 2 bytes for the "real" handler code.
  430. ;
  431. ; Next we get rid of the case where there are no parameters after &1.
  432. ; Then after that we deal with all the mutually exclusive special cases with
  433. ; nested if..endi sections.
  434.  
  435. CODE    macrox    &1,&2,&3,&4    ; label,flag,opt,alt-hndlr-code
  436.     if    "&3" <> ""
  437.     dc.w    pushDesc_h
  438.     dc.w    xinfoMk
  439.     dc.w    4
  440.     dc.w    &3
  441.     endi
  442.  
  443.     if    "&2" = ""
  444. &1_t    set    docode
  445.     Hcode    call_h,&4
  446. &1
  447.     else
  448.  
  449. &1_t    set    &2
  450.  
  451.     if    &2 = inline
  452.     inl    &1
  453.  
  454.     else
  455.  
  456.     if    &2 = doObj
  457.     Hcode    obj_h,&4
  458.     dc.w    6
  459.     dc.l    nilP_con
  460.     dc.w    -6
  461. &1
  462.     else
  463.  
  464.     if    &2 = doObjPtr
  465.     Hcode    objPtr_h,&4
  466. &1    dc.l    nilP_con
  467.     dc.l    0
  468.  
  469.     else
  470.  
  471.     if    &2 = xinfo
  472.     Hcode    call_h,&4
  473.     dc.w    xinfoMk
  474.     dc.w    &1-*-2
  475.  
  476.     else
  477.  
  478.     if    &2 = xinfoN
  479.     Hcode    call_h,&4
  480.     dc.w    xinfoMk
  481.     dc.w    0
  482.  
  483.     else
  484.  
  485.     if    ( &2 = docode ) or ( &2 = spec ) or ( &2 = docol ) or ( &2 = nocode )
  486.     Hcode    call_h,&4
  487. &1
  488.     endi
  489.     endi
  490.     endi
  491.     endi
  492.     endi
  493.     endi
  494.     endi
  495.     endm
  496.  
  497.  
  498. linkit    macrox    &1
  499.     if    q%1 = 0
  500.     dc.l    0
  501.     else
  502.     dc.l    q%1+d-*
  503.     endi
  504. q%1    set    *-d-4
  505.     endm
  506.  
  507. ; The HEAD macro defines a dictionary header.
  508. ; The flag field identifies what kind of word this is.  If the flag is
  509. ; "docol", "inline", "spec" or null, it is a word that is called
  510. ; by a JSR, and we assemble the handler field and linking code here.
  511. ; If the flag is anything else, we assume that HEAD has been called from
  512. ; another macro that is looking after everything, so we just assemble the 
  513. ; header.
  514. ; The opt field is non-zero if this word can begin a sequence where
  515. ; optimization of the compiled code is zero.  The opt field is left in 
  516. ; 2 bytes at the start of the definition; at compile time this field is
  517. ; left in CompFlg.
  518.  
  519. HEAD    macrox    &1,&2,&3,&4,&5,&6 ; len-byte,name,label,flag,opt,alt-hdlr
  520.     align
  521.     loc
  522.     linkit    &1 and 7
  523.     dc.b    &1 or $80
  524.     text    &&2
  525.     align
  526.     code    &3,&4,&5,&6
  527.     endm
  528.  
  529.  
  530. NOHEAD    macrox    &1,&2,&3,&4    ; label, flag, opt, alt-hdlr
  531.     code    &1,&2,&3,&4
  532.     endm
  533.  
  534.  
  535. COMH    macrox    &1
  536.     MOVEQ    #&1,D0
  537.     PUSH.L    D0
  538.     parms    wcomma
  539.     endm
  540.  
  541. CALLH    macrox    &1
  542.     if    "&1" <> ""
  543.     MOVEQ    #&1,D0
  544.     endi
  545.     BSR    CallHandlers
  546.     endm
  547.  
  548. JUMPH    macrox    &1
  549.     if    "&1" <> ""
  550.     MOVEQ    #&1,D0
  551.     endi
  552.     BRA    CallHandlers
  553.     endm
  554.  
  555.  
  556. NOOPT    macrox
  557.     bsr    doNoOpt
  558.     endm
  559.  
  560.  
  561. PARMS    macrox    &1,&2,&3,&4,&5,&6
  562.     token    &1
  563.     IF    "&2" <> ""
  564.     token    &2
  565.     ENDI
  566.     IF    "&3" <> ""
  567.     token    &3
  568.     ENDI
  569.     IF    "&4" <> ""
  570.     token    &4
  571.     ENDI
  572.     IF    "&5" <> ""
  573.     token    &5
  574.     ENDI
  575.     IF    "&6" <> ""
  576.     token    &6
  577.     ENDI
  578.     endm
  579.  
  580.  
  581. BRANCH    macrox    &1
  582.     BRA.S    &1
  583.     endm
  584.  
  585. QBRANCH    macrox    &1
  586.     TST.L    (A6)+
  587.     BNE.S    &1
  588.     endm
  589.  
  590. ZBRANCH    macrox    &1
  591.     TST.L    (A6)+
  592.     BEQ.S    &1
  593.     endm
  594.  
  595. EQBRANCH    macrox    &1,&2
  596.     CMPI.L    #&1,(A6)+
  597.     BEQ.S    &2
  598.     endm
  599.  
  600. NEBRANCH    macrox    &1,&2
  601.     CMPI.L    #&1,(A6)+
  602.     BNE.S    &2
  603.     endm
  604.  
  605. msg    macrox    &1
  606.     JSR    pdotq-base(a3)
  607.     text    #&&1
  608.     align
  609.     endm
  610.  
  611. abq    macrox    &1
  612.     JSR    pabq
  613.     text    #&&1
  614.     align
  615.     endm
  616.  
  617.  
  618. ; testing *************
  619. ;
  620. ;d
  621. ;
  622. ;q0    set    0
  623. ;q1    set    0
  624. ;q2    set    0
  625. ;q3    set    0
  626. ;q4    set    0
  627. ;q5    set    0
  628. ;q6    set    0
  629. ;q7    set    0
  630. ;
  631. ;    dc.w    123
  632. ;
  633. ;    head    5,BLOGGS,bloggs
  634. ;    dc.l    9876
  635. ;
  636. ;    valu    4,HAHA,haha,25
  637. ;
  638. ; "Push a descriptor" test
  639. ;otCMP    equ    $26
  640. ;tsGE    equ    otCMP*256 + $C
  641. ;setTrue
  642. ;setFalse
  643. ;
  644. ;    head    2,>=,ge,docode,tsGE
  645. ;    CMPM.L    (A6)+,(A6)+
  646. ;    BGE.S    setTrue
  647. ;    BRA.S    setFalse
  648. ;
  649. ; Push a descriptor with inline
  650. ;nip_m    macrox
  651. ;    POP.L    (A6)
  652. ;    endm
  653. ;    head    3,NIP,nip,inline,tsCCOK
  654. ;
  655. ; "xinfo" test
  656. ;    head    3,YYY,yyy,xinfo
  657. ;    dc.w    123
  658. ;    dc.w    456
  659. ;yyy    moveq    #1,d0
  660. ;    rts
  661. ;
  662. ; xinfo with inline
  663. ;
  664. ;otADD    equ    $21
  665. ;
  666. ;plus_m    macrox
  667. ;    POP.L    D0
  668. ;    ADD.L    D0,(A6)
  669. ;    endm
  670. ;
  671. ;    head    1,+,plus,xinfo,,pm_h
  672. ;    dc.w    otADD
  673. ;    use    plus
  674. ;
  675. ;
  676. ;    head    7,LOCPARM,locparm,nocode,,loc_h
  677. ;
  678. ;
  679. ;    varbl    7,CONTEXT,context
  680. ;
  681. ;    dc.l    q0+d-*
  682. ;    dc.l    q1+d-*
  683. ;    dc.l    q2+d-*
  684. ;    dc.l    q3+d-*
  685. ;    dc.l    q4+d-*
  686. ;    dc.l    q5+d-*
  687. ;    dc.l    q6+d-*
  688. ;    dc.l    q7+d-*
  689. ;
  690. ;